package com.bosssoft.trainee.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.trainee.entity.po.Route;
import com.bosssoft.trainee.mapper.RouteMapper;
import com.bosssoft.trainee.service.RouteService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author liuqiang
 * @date 2022/7/19 11:19
 */
@Service
public class RouteServiceImp extends ServiceImpl<RouteMapper, Route> implements RouteService {

    public List<Route> getRoutesByRole(Integer roleId){
        QueryWrapper<Route> menuQueryWrapper = new QueryWrapper<>();
        menuQueryWrapper.eq("role_id",roleId);
        List<Route> list;
        list = this.list(menuQueryWrapper);
        return list;
    }
    public Route getRouteByParentId(Integer parentId){
        QueryWrapper<Route> menuQueryWrapper = new QueryWrapper<>();
        menuQueryWrapper.eq("route_id",parentId);
        return this.getOne(menuQueryWrapper);
    }
    public Map<String,Object> getRoutesMap(Route route){
        Map<String,Object> map = new HashMap<>();
        map.put("path",route.getRoutePath());
        map.put("name",route.getRouteName());
        map.put("component",route.getRouteComponent());
        //
        if(route.getRouteRedirect()!=null){
            map.put("redirect",route.getRouteRedirect());
        }
        return map;
    }
    public Map<String,Object> getMetaMap(Route route){
        Map<String,Object> meta = new HashMap<>();
        meta.put("title",route.getRouteMetaTitle());
        //
        meta.put("icon",route.getRouteMetaIcon());
        return meta;
    }


    public List<Route> getRoutesByPath(List<String> list){
        List<Route> routeList = new ArrayList<>();
        for(String s : list){
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.eq("path",s);
            Route route = this.getOne(queryWrapper);
            routeList.add(route);
        }
        return routeList;
    }
}
